package com.lc202408;

import java.util.Arrays;

public class Solution896 {
    public boolean isMonotonic(int[] nums) {
        int length = nums.length;
        if (length <= 2) {
            return true;
        }
        int size = length - 1;
        int[] arr = new int[size];
        for (int i = 1; i < length; i++) {
            arr[i - 1] = nums[i] - nums[i - 1];
        }
        long count1 = Arrays.stream(arr).filter(i -> i >= 0).count();
        long count2 = Arrays.stream(arr).filter(i -> i <= 0).count();
        return count1 == size || count2 == size;
    }
}
